package cn.bon.user.controller;

import cn.bon.common.bean.JsonResult;
import cn.bon.user.pojo.dto.UserAddDTO;
import cn.bon.user.pojo.po.UserPo;
import cn.bon.user.pojo.vo.UserLoginVO;
import cn.bon.user.pojo.vo.UserVO;
import cn.bon.user.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: dronff
 * @description:
 * @CreateTime: 2023/12/8 9:32
 **/

@RestController
@RequestMapping("/user")
@Schema(description = "用户的增删改查")
public class UserController {
    @Resource
    private UserService userService;


    @PostMapping("/addUser")
    @Operation(summary = "增加用户")
//    @PreAuthorize("hasAnyAuthority('admin')")
    public JsonResult<UserPo> addUser(@RequestBody UserAddDTO userAddDTO){
        return userService.addUser(userAddDTO);
    }

    @DeleteMapping("/deleteUserById/{userId}")
    @Operation(summary = "删除用户")
    public JsonResult<UserPo> deleteUserById(int userId){
        return userService.deleteUserById(userId);
    }

    @GetMapping("/pageUsers")
    @Operation(summary = "根据条件获取用户")
    public JsonResult<List<UserVO>> pageUsers(@RequestParam(value = "name", required = false) @Parameter(description = "员工名")
                                                  String name,
                                              @RequestParam(value = "orgName",required = false) @Parameter(description = "机构名")
                                                  String orgName){
        return userService.pageUsers(name,orgName);
    }
}
